<?php


namespace App\Models\Pay;


use App\Models\IFace\Pay;
use App\User;

class WxPay extends PayFormat implements Pay
{
    public static function Pay($order, $notifyUrl)
    {
        $user = User::find($order['user_id']);
        if (empty($user)) {
            uexception('用户不存在');
        }
        $pay_data = [
            'openid' => $user['openid'],
            'out_trade_no' => $order['no'],
            'body' => '订单支付',
            'total_fee' => $order['total_amount'] * 100,
            //'total_fee' => 1,
        ];
        $config = config('pay.wechat');
        $config['notify_url'] = $notifyUrl;
        $pay = \Yansongda\Pay\Pay::wechat($config)->miniapp($pay_data);
        $result = self::format($pay->toArray());
        return $result;
    }
}